<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * Page Config->Plugin
 * Edit Plugins configdata
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2015
 * @author     Norbert Gebert
 * @license    GPL3
 */
function contentPage($refPage, $page, $subpage, $refValidate)
{
	$refPage->assign('messagebox', '');

	if (isset($_GET['func']))
	{
		if ($refValidate->cleanslash($_GET['func']) === 'edit')
		{ // edit tax
			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.editor.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
	}
	else if (isset($_REQUEST['submit']))
	{
		if ($refValidate->cleanslash($_REQUEST['submit']) === _('Save'))
		{ // Save values from Form 
			xplugin::saveValues($refValidate->cleanslash($_POST['idx']));

			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
		else if ($refValidate->cleanslash($_REQUEST['submit']) === _('Delete entry'))
		{ // Delete marked XPluginentry
			foreach ($_POST['marker'] as $idx)
			{
				$idx = $refValidate->cleanslash($idx);
				db::getInstance()->where('plugin_id', $idx);
				if (db::getInstance()->delete('plugin'))
				{
					message::setNoteRow(_('Entry successful deleted.'), TRUE);
				}
				else
				{
					message::setErrorRow(_('Entry could not be deleted!'), TRUE);
				}
			}

			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
		else if ($refValidate->cleanslash($_REQUEST['submit']) === _('Search new plugins'))
		{ // Automaticly read and test of plugins
			xplugin::getNewPlugin();

			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
		else if ($refValidate->cleanslash($_REQUEST['submit']) === _('Cancel'))
		{ // browse tax xxxxxxxxxxxxxx
			$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
			if (is_file($pagefile))
				include_once $pagefile;
		}
	}
	else
	{ // browse pluginlist
		$pagefile = 'module/page/' . $page . '/' . $subpage . '.page.table.php';
		if (is_file($pagefile))
			include_once $pagefile;
	}
}

?>